#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>

#include "../lib/inc/cppjieba/Jieba.hpp"
#include "log.hpp"
namespace ns_util
{
	using namespace ns_log;

	class FileUtil
	{
		public:
			static bool ReadFile(const std::string &file_path,std::string *out)
			{
				std::ifstream in(file_path,std::ios::in);
				if(! in.is_open())
				{
					LOG(ERROR) << "open file" << file_path << "error" <<std::endl;
					return false;
				}

				std::string line;
				//如何理解getline读取到文件结束呢？？getline的返回值是一个istream&，while(bool), 本质是因为重载了强制类型转化
				while(std::getline(in,line))	
				{
					*out += line;
				}


				in.close();
				return true;
			}	
	};

	//分割字符串
	class StringUtil
	{
		public:
		//target要分割的字符串
		//out 分割后输出的
		//sep 分割符
		//token_compress_on 有连续分割符要不要
		static void Split(const std::string& target,std::vector<std::string> *out,const std::string& sep)
		{
			boost::split(*out,target,boost::is_any_of(sep),boost::token_compress_on);
		}
	};

	const char *const DICT_PATH = "../lib/dict/jieba.dict.utf8";
	const char *const HMM_PATH = "../lib/dict/hmm_model.utf8";
	const char *const USER_DICT_PATH = "../lib/dict/user.dict.utf8";
	const char *const IDF_PATH = "../lib/dict/idf.utf8";
	const char *const STOP_WORD_PATH = "../lib/dict/stop_words.utf8";

	class JiebaUtil
	{
		private:
			static cppjieba::Jieba Jieba;
		public:
			static void CutString(const std::string& src , std::vector<std::string>* out)
			{
				Jieba.CutForSearch(src,*out);
			}
	};

	cppjieba::Jieba JiebaUtil::Jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,IDF_PATH,STOP_WORD_PATH);
}